package com.qdu.servlet;

import com.qdu.entity.Worker;
import com.qdu.service.WorkerService;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 根据员工编号查询单个工作人员（导演或演员）的Servlet
 *
 * @author Anna
 */
@WebServlet("/gwis")
public class GetWorkerInfoServlet extends HttpServlet {

    WorkerService workerService = new WorkerService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1. 获取请求参数
        //获取提交的员工编号
        String workerId = req.getParameter("workerId");

        //2. 执行业务逻辑 
        //调用WorkerService类的findWorkerById()方法根据员工编号查询员工的个人信息
        Worker worker = workerService.findWorkerById(workerId);

        //3. 生成动态响应
        //将Worker对象作为属性添加到请求对象中，转发请求共享给worker_info.jsp页面显示
        req.setAttribute("worker", worker);
        req.getRequestDispatcher("/worker_info.jsp").forward(req, resp);
    }
}
